package leetcode.array;

import java.util.Arrays;
import java.util.List;
import java.util.Scanner;
import java.util.stream.Collectors;

/**
 * leetCode 169
 * 求众数（出现超过一半的数）

 */
public class Array169 {

    public static void main(String []args){
        Scanner sc = new Scanner(System.in);
        String str = sc.next();
        List<Integer> input = Arrays.stream(str.split(",")).map(i -> { return Integer.parseInt(i); }).collect(Collectors.toList());
        System.out.println(Arrays.toString(input.toArray()));
        Integer [] nums = input.toArray(new Integer[input.size()]);
        new Array169().majorityElement(nums);
    }
    public int majorityElement(Integer[] nums) {
        int x = 0;
        int count = 1;
        for(int i =0;i<nums.length;i++){
            if(nums[i] != x){
                count --;
            } else{
                count ++;
            }
            if(count == 0){
                x = nums[i];
                count = 1;
            }
        }
        return x;
    }
}
